//
//  FXEventProxyType.swift
//  FXEvent
//
//  Created by Fanxx on 2021/11/23.
//

import Foundation

/// 事件代理，可代为触发事件
public protocol FXEventProxyType: FXEventType where ParameterType == EventType.ParameterType {
    associatedtype EventType: FXEventType
    /// 被代理事件
    var event: EventType { get set }
}
extension FXEventProxyType {
    public typealias ParameterType = EventType.ParameterType
    public var isEnabled: Bool {
        get {
            return self.event.isEnabled
        }
        set {
            self.event.isEnabled = newValue
        }
    }
    /// 添加事件处理
    public func addTarget(_ target: AnyObject, action: Selector) {
        self.event.addTarget(target, action: action)
    }
    /// 移除事件处理
    public func removeTarget(_ target: AnyObject, action: Selector) {
        self.event.removeTarget(target, action: action)
    }
    /// 移除事件处理
    public func removeTarget(_ target: AnyObject) {
        self.event.removeTarget(target)
    }
    /// 添加事件处理
    public func addBlock(_ identifier: String, block: @escaping (ParameterType) -> Void) {
        self.event.addBlock(identifier, block: block)
    }
    /// 添加事件处理
    public func addBlock(_ block: @escaping (ParameterType) -> Void) {
        self.event.addBlock(block)
    }
    /// 移除事件处理
    public func removeBlock(_ identifier: String) {
        self.event.removeBlock(identifier)
    }
    /// 移除全部事件处理
    public func removeAllActions() {
        self.event.removeAllActions()
    }
    /// 触发事件
    public func sendActions(for parameter: ParameterType) {
        self.event.sendActions(for: parameter)
    }
}
